package com.duowei.diandan.db.entry;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.PrimaryKey;

import com.duowei.diandan.app.OrderList;
import com.duowei.diandan.bean.food.FoodImpl;
import com.duowei.diandan.constant.Settings;

import org.joda.time.LocalDateTime;

import java.io.Serializable;
import java.util.Objects;

/**
 * 单品信息
 */
@SuppressWarnings("ALL")
@Entity
public class Jyxmsz implements FoodImpl, Serializable {
    @PrimaryKey(autoGenerate = true)
    private long id;

    /** 项目编号 */
    private String xmbh;
    /** 项目名称 */
    private String xmmc;
    /** 字头拼音 */
    private String py;
    /** 内部编号 */
    private String tm;
    /** 单位 */
    private String dw;
    /** 类别编码（关联DMJYXMSSLB中的lbbm） */
    private String lbbm;
    /** 类别名称 */
    private String lbmc;
    /** 销售价格 */
    private Float xsjg;
    private Float zkd;
    private Float hyzk;
    private String sfjf;
    /** 是否为套餐 (1套餐标示) */
    private String sftc;
    /** 是否沽清 （1沽清） */
    private String gq;
    private String dyjbh;
    private Integer tczxgs;
    /** 必选口味 */
    private String sfyhq;
    /** 兑换该单品所需积分 */
    private Float yhj;
    private Float hyj;
    private Float cbjg;
    private Float ysjg;
    /** 是否停用（1停用） */
    private String sfqx;
    private String sfsc;
    private String bcyzddz;
    /** 排序号 */
    private Float xl;
    /** 会员价1-9 */
    private Float hyj2;
    private Float hyj3;
    private Float hyj4;
    private Float hyj5;
    private Float hyj6;
    private Float hyj7;
    private Float hyj8;
    private Float hyj9;
    /** 按钮显示颜色 */
    private String hlbmmc;
    private String by1;
    /** 打印机ip */
    private String by2;
    /** 是否重生鲜商品 （1是） */
    private String by3;
    /** 记为来客数 */
    private String by4;
    private Float by5;
    /** 获取积分 */
    private Float by6;
    private Float by7;
    private LocalDateTime by8;
    private LocalDateTime by9;
    private String gg;
    private String sfmrpc;
    private String sfmzpc;
    /** 是否时价单品（1时价单品） */
    private String sfmypc;
    private String wbzdw;
    private String nbzdw;
    private Float wndwzhl;
    private Float dwzhl;
    private String sfjg;
    private Float ckjg;
    private Float dqkcsl;
    private String gysbh;
    private String by10;
    private String by11;
    /** 是否可使用抵用券（1不能使用） */
    private String by12;
    private String by13;
    private String by14;
    private String by15;
    /** 偶数份半价 */
    private String by16;
    private String bmbh;
    private String by17;
    private String by18;
    private String by19;
    private String by20;
    private String by21;

    // 以下自定义字段

    // 单品分类
    @Ignore
    private Dmjyxmsslb dmjyxmsslb;

    /** 买赠、加价时，保存的数量 */
    @Ignore
    private float sl = 1;

    public Jyxmsz() {
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getXmbh() {
        return xmbh;
    }

    public void setXmbh(String xmbh) {
        this.xmbh = xmbh;
    }

    public String getXmmc() {
        return xmmc;
    }

    public void setXmmc(String xmmc) {
        this.xmmc = xmmc;
    }

    public String getPy() {
        return py;
    }

    public void setPy(String py) {
        this.py = py;
    }

    public String getTm() {
        return tm;
    }

    public void setTm(String tm) {
        this.tm = tm;
    }

    public String getDw() {
        return dw;
    }

    public void setDw(String dw) {
        this.dw = dw;
    }

    public String getLbbm() {
        return lbbm;
    }

    public void setLbbm(String lbbm) {
        this.lbbm = lbbm;
    }

    public String getLbmc() {
        return lbmc;
    }

    public void setLbmc(String lbmc) {
        this.lbmc = lbmc;
    }

    public Float getXsjg() {
        return xsjg;
    }

    public void setXsjg(Float xsjg) {
        this.xsjg = xsjg;
    }

    public Float getZkd() {
        return zkd;
    }

    public void setZkd(Float zkd) {
        this.zkd = zkd;
    }

    public Float getHyzk() {
        return hyzk;
    }

    public void setHyzk(Float hyzk) {
        this.hyzk = hyzk;
    }

    public String getSfjf() {
        return sfjf;
    }

    public void setSfjf(String sfjf) {
        this.sfjf = sfjf;
    }

    public String getSftc() {
        return sftc;
    }

    public void setSftc(String sftc) {
        this.sftc = sftc;
    }

    public String getGq() {
        return gq;
    }

    public void setGq(String gq) {
        this.gq = gq;
    }

    public String getDyjbh() {
        return dyjbh;
    }

    public void setDyjbh(String dyjbh) {
        this.dyjbh = dyjbh;
    }

    public Integer getTczxgs() {
        return tczxgs;
    }

    public void setTczxgs(Integer tczxgs) {
        this.tczxgs = tczxgs;
    }

    public String getSfyhq() {
        return sfyhq;
    }

    public void setSfyhq(String sfyhq) {
        this.sfyhq = sfyhq;
    }

    public Float getYhj() {
        return yhj;
    }

    public void setYhj(Float yhj) {
        this.yhj = yhj;
    }

    public Float getHyj() {
        return hyj;
    }

    public void setHyj(Float hyj) {
        this.hyj = hyj;
    }

    public Float getCbjg() {
        return cbjg;
    }

    public void setCbjg(Float cbjg) {
        this.cbjg = cbjg;
    }

    public Float getYsjg() {
        return ysjg;
    }

    public void setYsjg(Float ysjg) {
        this.ysjg = ysjg;
    }

    public String getSfqx() {
        return sfqx;
    }

    public void setSfqx(String sfqx) {
        this.sfqx = sfqx;
    }

    public String getSfsc() {
        return sfsc;
    }

    public void setSfsc(String sfsc) {
        this.sfsc = sfsc;
    }

    public String getBcyzddz() {
        return bcyzddz;
    }

    public void setBcyzddz(String bcyzddz) {
        this.bcyzddz = bcyzddz;
    }

    public Float getXl() {
        return xl;
    }

    public void setXl(Float xl) {
        this.xl = xl;
    }

    public Float getHyj2() {
        return hyj2;
    }

    public void setHyj2(Float hyj2) {
        this.hyj2 = hyj2;
    }

    public Float getHyj3() {
        return hyj3;
    }

    public void setHyj3(Float hyj3) {
        this.hyj3 = hyj3;
    }

    public Float getHyj4() {
        return hyj4;
    }

    public void setHyj4(Float hyj4) {
        this.hyj4 = hyj4;
    }

    public Float getHyj5() {
        return hyj5;
    }

    public void setHyj5(Float hyj5) {
        this.hyj5 = hyj5;
    }

    public Float getHyj6() {
        return hyj6;
    }

    public void setHyj6(Float hyj6) {
        this.hyj6 = hyj6;
    }

    public Float getHyj7() {
        return hyj7;
    }

    public void setHyj7(Float hyj7) {
        this.hyj7 = hyj7;
    }

    public Float getHyj8() {
        return hyj8;
    }

    public void setHyj8(Float hyj8) {
        this.hyj8 = hyj8;
    }

    public Float getHyj9() {
        return hyj9;
    }

    public void setHyj9(Float hyj9) {
        this.hyj9 = hyj9;
    }

    public String getHlbmmc() {
        return hlbmmc;
    }

    public void setHlbmmc(String hlbmmc) {
        this.hlbmmc = hlbmmc;
    }

    public String getBy1() {
        return by1;
    }

    public void setBy1(String by1) {
        this.by1 = by1;
    }

    public String getBy2() {
        return by2;
    }

    public void setBy2(String by2) {
        this.by2 = by2;
    }

    public String getBy3() {
        return by3;
    }

    public void setBy3(String by3) {
        this.by3 = by3;
    }

    public String getBy4() {
        return by4;
    }

    public void setBy4(String by4) {
        this.by4 = by4;
    }

    public Float getBy5() {
        return by5;
    }

    public void setBy5(Float by5) {
        this.by5 = by5;
    }

    public Float getBy6() {
        return by6;
    }

    public void setBy6(Float by6) {
        this.by6 = by6;
    }

    public Float getBy7() {
        return by7;
    }

    public void setBy7(Float by7) {
        this.by7 = by7;
    }

    public LocalDateTime getBy8() {
        return by8;
    }

    public void setBy8(LocalDateTime by8) {
        this.by8 = by8;
    }

    public LocalDateTime getBy9() {
        return by9;
    }

    public void setBy9(LocalDateTime by9) {
        this.by9 = by9;
    }

    public String getGg() {
        return gg;
    }

    public void setGg(String gg) {
        this.gg = gg;
    }

    public String getSfmrpc() {
        return sfmrpc;
    }

    public void setSfmrpc(String sfmrpc) {
        this.sfmrpc = sfmrpc;
    }

    public String getSfmzpc() {
        return sfmzpc;
    }

    public void setSfmzpc(String sfmzpc) {
        this.sfmzpc = sfmzpc;
    }

    public String getSfmypc() {
        return sfmypc;
    }

    public void setSfmypc(String sfmypc) {
        this.sfmypc = sfmypc;
    }

    public String getWbzdw() {
        return wbzdw;
    }

    public void setWbzdw(String wbzdw) {
        this.wbzdw = wbzdw;
    }

    public String getNbzdw() {
        return nbzdw;
    }

    public void setNbzdw(String nbzdw) {
        this.nbzdw = nbzdw;
    }

    public Float getWndwzhl() {
        return wndwzhl;
    }

    public void setWndwzhl(Float wndwzhl) {
        this.wndwzhl = wndwzhl;
    }

    public Float getDwzhl() {
        return dwzhl;
    }

    public void setDwzhl(Float dwzhl) {
        this.dwzhl = dwzhl;
    }

    public String getSfjg() {
        return sfjg;
    }

    public void setSfjg(String sfjg) {
        this.sfjg = sfjg;
    }

    public Float getCkjg() {
        return ckjg;
    }

    public void setCkjg(Float ckjg) {
        this.ckjg = ckjg;
    }

    public Float getDqkcsl() {
        return dqkcsl;
    }

    public void setDqkcsl(Float dqkcsl) {
        this.dqkcsl = dqkcsl;
    }

    public String getGysbh() {
        return gysbh;
    }

    public void setGysbh(String gysbh) {
        this.gysbh = gysbh;
    }

    public String getBy10() {
        return by10;
    }

    public void setBy10(String by10) {
        this.by10 = by10;
    }

    public String getBy11() {
        return by11;
    }

    public void setBy11(String by11) {
        this.by11 = by11;
    }

    public String getBy12() {
        return by12;
    }

    public void setBy12(String by12) {
        this.by12 = by12;
    }

    public String getBy13() {
        return by13;
    }

    public void setBy13(String by13) {
        this.by13 = by13;
    }

    public String getBy14() {
        return by14;
    }

    public void setBy14(String by14) {
        this.by14 = by14;
    }

    public String getBy15() {
        return by15;
    }

    public void setBy15(String by15) {
        this.by15 = by15;
    }

    public String getBy16() {
        return by16;
    }

    public void setBy16(String by16) {
        this.by16 = by16;
    }

    public String getBmbh() {
        return bmbh;
    }

    public void setBmbh(String bmbh) {
        this.bmbh = bmbh;
    }

    public String getBy17() {
        return by17;
    }

    public void setBy17(String by17) {
        this.by17 = by17;
    }

    public String getBy18() {
        return by18;
    }

    public void setBy18(String by18) {
        this.by18 = by18;
    }

    public String getBy19() {
        return by19;
    }

    public void setBy19(String by19) {
        this.by19 = by19;
    }

    public String getBy20() {
        return by20;
    }

    public void setBy20(String by20) {
        this.by20 = by20;
    }

    public String getBy21() {
        return by21;
    }

    public void setBy21(String by21) {
        this.by21 = by21;
    }

    public Dmjyxmsslb getDmjyxmsslb() {
        return dmjyxmsslb;
    }

    public void setDmjyxmsslb(Dmjyxmsslb dmjyxmsslb) {
        this.dmjyxmsslb = dmjyxmsslb;
    }

    public float getSl() {
        return sl;
    }

    public void setSl(float sl) {
        this.sl = sl;
    }

    // -----
    @Override
    public String getImgNo() {
        return this.tm;
    }

    @Override
    public String getName() {
        return this.xmmc;
    }

    @Override
    public Float getPrice() {
        Float memberPrice = getMemberPrice();
        if (memberPrice != null) {
            if (memberPrice < this.xsjg) {
                return memberPrice;
            } else {
                return this.xsjg;
            }
        } else {
            return this.xsjg;
        }

    }

    @Override
    public Float getMemberPrice() {
        Float price = null;

        switch (OrderList.getInstance().getCurrentMemberGrade()) {
            case 0:
                price = null;
                break;
            case 1:
                if (this.hyj != null && this.hyj > 0) {
                    price = this.hyj;
                }
                break;
            case 2:
                if (this.hyj2 != null && this.hyj2 > 0) {
                    price = this.hyj2;
                }
                break;
            case 3:
                if (this.hyj3 != null && this.hyj3 > 0) {
                    price = this.hyj3;
                }
                break;
            case 4:
                if (this.hyj4 != null && this.hyj4 > 0) {
                    price = this.hyj4;
                }
                break;
            case 5:
                if (this.hyj5 != null && this.hyj5 > 0) {
                    price = this.hyj5;
                }
                break;
            case 6:
                if (this.hyj6 != null && this.hyj6 > 0) {
                    price = this.hyj6;
                }
                break;
            case 7:
                if (this.hyj7 != null && this.hyj7 > 0) {
                    price = this.hyj7;
                }
                break;
            case 8:
                if (this.hyj8 != null && this.hyj8 > 0) {
                    price = this.hyj8;
                }
                break;
            case 9:
                if (this.hyj9 != null && this.hyj9 > 0) {
                    price = this.hyj9;
                }
                break;
        }

        return price;
    }
    // -----

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Jyxmsz) {
            Jyxmsz j = (Jyxmsz) obj;

            return Objects.equals(this.xmmc, j.xmmc)
                    && Objects.equals(this.gq, j.gq)
                    && Objects.equals(this.xsjg, j.xsjg)
                    && Objects.equals(this.hyj, j.hyj)
                    && Objects.equals(this.hyj2, j.hyj2)
                    && Objects.equals(this.hyj3, j.hyj3)
                    && Objects.equals(this.hyj4, j.hyj4)
                    && Objects.equals(this.hyj5, j.hyj5)
                    && Objects.equals(this.hyj6, j.hyj6)
                    && Objects.equals(this.hyj7, j.hyj7)
                    && Objects.equals(this.hyj8, j.hyj8)
                    && Objects.equals(this.hyj9, j.hyj9);

        } else {
            return false;

        }
    }

    public static String querySql() {
        if (Settings.ONLY_SHOW_BY21) {
            return sql21();

        } else {
            return sql0();
        }
    }

    private static String sql0() {
//        return "SELECT xmbh, xmmc, py, tm, dw, lbbm, lbmc, xsjg, zkd, hyzk, sfjf, sftc, gq, " +
//                "dyjbh, tczxgs, sfyhq, yhj, hyj, cbjg, ysjg, sfqx, sfsc, bcyzddz, xl, hyj2, " +
//                "hyj3, hyj4, hyj5, hyj6, hyj7, hyj8, hyj9, hlbmmc, by1, by2, by3, by4, by5, " +
//                "by6, by7, by8, by9, gg, sfmrpc, sfmzpc, sfmypc, wbzdw, nbzdw, wndwzhl, dwzhl, " +
//                "sfjg, ckjg, dqkcsl, gysbh, by10, by11, by12, by13, by14, by15, by16, bmbh, " +
//                "by17, by18, by19, by20 from jyxmsz where isnull(sfqx, 0) != '1'|";

        return "SELECT xmbh, xmmc, py, tm, dw, lbbm, lbmc, xsjg, zkd, hyzk, sfjf, sftc, gq, " +
                "dyjbh, tczxgs, sfyhq, yhj, hyj, cbjg, ysjg, sfqx, sfsc, bcyzddz, xl, hyj2, " +
                "hyj3, hyj4, hyj5, hyj6, hyj7, hyj8, hyj9, hlbmmc, by1, by2, by3, by4, by5, " +
                "by6, by7, by8, by9, gg, sfmrpc, sfmzpc, sfmypc, wbzdw, nbzdw, wndwzhl, dwzhl, " +
                "sfjg, ckjg, dqkcsl, gysbh, by10, by11, by12, by13, by14, by15, by16, bmbh, " +
                "by17, by18, by19, by20 from jyxmsz|";
    }

    private static String sql21() {
//        return "SELECT xmbh, xmmc, py, tm, dw, lbbm, lbmc, xsjg, zkd, hyzk, sfjf, sftc, gq, " +
//                "dyjbh, tczxgs, sfyhq, yhj, hyj, cbjg, ysjg, sfqx, sfsc, bcyzddz, xl, hyj2, " +
//                "hyj3, hyj4, hyj5, hyj6, hyj7, hyj8, hyj9, hlbmmc, by1, by2, by3, by4, by5, " +
//                "by6, by7, by8, by9, gg, sfmrpc, sfmzpc, sfmypc, wbzdw, nbzdw, wndwzhl, dwzhl, " +
//                "sfjg, ckjg, dqkcsl, gysbh, by10, by11, by12, by13, by14, by15, by16, bmbh, " +
//                "by17, by18, by19, by20, by21 from jyxmsz " +
//                "where isnull(by21, 0) = '1' and isnull(sfqx, 0) != '1'|";

        return "SELECT xmbh, xmmc, py, tm, dw, lbbm, lbmc, xsjg, zkd, hyzk, sfjf, sftc, gq, " +
                "dyjbh, tczxgs, sfyhq, yhj, hyj, cbjg, ysjg, sfqx, sfsc, bcyzddz, xl, hyj2, " +
                "hyj3, hyj4, hyj5, hyj6, hyj7, hyj8, hyj9, hlbmmc, by1, by2, by3, by4, by5, " +
                "by6, by7, by8, by9, gg, sfmrpc, sfmzpc, sfmypc, wbzdw, nbzdw, wndwzhl, dwzhl, " +
                "sfjg, ckjg, dqkcsl, gysbh, by10, by11, by12, by13, by14, by15, by16, bmbh, " +
                "by17, by18, by19, by20, by21 from jyxmsz|";
    }
}
